// pages/locationSearch/locationSearch.js
//刘丽丽 2019-03-06
var call = require("../../utils/request.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {

    nearVillageBox: [
      {
        houseName: '高尔夫花园',
        houseAddress: '金鸡湖大道',
      },
    ],
    keywords:'',//关键词搜索
    communityView: ''//无数据显示/隐藏(1--有数据，0--无数据)

  },

  //关键词搜索
  keyword:function(event){
    var that = this
    console.log(event.detail.value)
    that.setData({
      keywords: event.detail.value
    })
  },
  //点击搜索事件
  shearch:function(){
    var that = this
    var chooseid = wx.getStorageSync("chooseid")
    var thekeyword = that.data.keywords
    console.log(thekeyword)
    console.log("chooseid:" + chooseid)
    if (chooseid == ""){
      wx.showToast({
        title: '请选择城市',
        icon: 'none',
        duration: 2000
      })
    }else{
      var parms = {
        cityId: chooseid,
        keyWord: thekeyword
      }
      call.request("house/getHouseList", parms, this.thechange, this.fail);
    }
  },
  //成功执行 搜索小区
  thechange:function(data){
    var that = this
    if (data.msg == "success" && data.data !=""){
      that.setData({
        nearVillageBox: data.data,
        communityView:1
      })
    }else{
      that.setData({
        communityView: 0
      })
    }   
  },
  //取消
  cancel:function(){
    wx.navigateBack({
      delta: 2
    })
  },
  //失败
  fail:function(){
    console.log("失败")
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    var that = this
    var chooseid = wx.getStorageSync("chooseid")
    var parms = {
      cityId: chooseid,
      keyWord: that.data.keywords
    }
    call.request("house/getHouseList", parms, this.thechange, this.fail);
  },

  /**
   * 生命周期函数--监听页面显示
   */

  onShow: function () {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})